package org.wcf.util.freeMarker;

import org.apache.commons.lang3.StringUtils;
import org.wcf.util.StringsUtil;

import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author wuchaofei
 * @date 2016/3/22
 */
public class BeanGen {
    public static void main(String[] args) {
//        genBean("rush_attr_group","out/bean","id,name,desc,category_id");
        String s="pic=/wap/20140226/default/29797322205884312,\n" +
                "        rush_id=64,\n" +
                "        price=5979,\n" +
                "        zhu_pid=,\n" +
                "        rushInfo=DSuN7g1EB_86_1_,\n" +
                "        PJugthMTI_86_2_,\n" +
                "        PJulCqqyM_86_1_,\n" +
                "        info=<p>赠品A套餐：客厅电视X60（4999）+乐视网TV版24个月服务费（980）+超级遥控器+云底座</p>,\n" +
                "        name=超级电视X60套餐A限量2500台";
        genBean("RushExtraInfo","out/bean", StringsUtil.collectKey(s));

    }
    public static void genBean(String className,String toFile,String dataStr){
        String[] datas={};
        if(StringUtils.isNotEmpty(dataStr)){
            datas = dataStr.split(",");
        }

        Map<String,Object> map=new HashMap<String,Object>();
        map.put("attrs", Arrays.asList(datas));

        className = FreemarkerUtil.splitJoinUpperFirstWord(className);
        map.put("className",FreemarkerUtil.toUpperCaseFirstOne(className));
        //文件夹名添加文件名
        toFile = new File(toFile,FreemarkerUtil.toUpperCaseFirstOne(className+".java")).getAbsolutePath();
        FreemarkerUtil.genBean(className,toFile,map);
    }

}
